/*
-----------------------------------------------------------------------------
This file is part of NxGraphics, Multimedia Engine.
Author : Stephane Kyles. Developed in Prague, Czech Republic.
				_   __       __  ___                         
			   / | / /_  __ /  |/  /____   _____ ____ _ ____ 
			  /  |/ /| |/_// /|_/ // __ \ / ___// __ `// __ \
			 / /|  /_>  < / /  / // /_/ // /__ / /_/ // /_/ /
			/_/ |_//_/|_|/_/  /_/ \____/ \___/ \__,_// .___/ 
													/_/      
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef __NXMOCAPSOCKET_H__
#define __NXMOCAPSOCKET_H__

#include "NxMocap_Prerequisites.h"

namespace NxMocap_Namespace {

static int  nofSockets_  = 0 ;

enum TypeSocket{
	BlockingSocket,
	NonBlockingSocket
};

class NxMocap_Export Socket 
{
public:
	Socket();
	virtual ~Socket();
	Socket(const Socket& o);
	Socket& operator=(Socket& o);
	std::string ReceiveBytes();
	void Close();
	void SendLine( std::string s );
	int SendBytes( BYTE * bytes , int much );
	friend class SocketServer;
	friend class SocketSelect;
	Socket(SOCKET s);
	int* refCounter_;
	SOCKET s_;

private:
	static void Start();
	static void End();
};

class NxMocap_Export SocketClient : public Socket
{
public:
	SocketClient(const std::string& host, int port);
};

class NxMocap_Export SocketServer : public Socket 
{
public:
	SocketServer( int port, int connections, TypeSocket type = BlockingSocket );
	Socket * Accept();

};

}

#endif
